package com.anda.account.infrastructure.persistence;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.anda.account.constant.LoginState;
import com.anda.account.domain.model.system.User;
import com.anda.account.infrastructure.persistence.generic.BaseDaoImpl;

@Repository("userDao")
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {

	public LoginState getUserLoginState(User user) {
		String hql = "from User o where (o.userName=? or o.userAccount=?) and o.userPwd=?";
		List users = getHibernateTemplate().find(hql, user.getUserName(), user.getUserName(), user.getUserPwd());
		if (users.isEmpty()) {
			return LoginState.ERROR_PWD_USER;
		} else {
			return LoginState.PASS;
		}
	}
	
	public User getLoginUser(User user) {
		String hql = "from User o where (o.userName=? or o.userAccount=?) and o.userPwd=?";
		List users = getHibernateTemplate().find(hql, user.getUserName(), user.getUserName(), user.getUserPwd());
		return (User) users.listIterator().next();
	}

}
